import java.util.*;

class Solution {

    /* Write Code Here */
    public int[] ThreeDigitNumbers (int[] selectedDigits) {
        int[] ret = new int[60];
        int[] flg = new int[5];
        int count = 0;
        for(int i = 0; i < 5; i++) {
            int tmp = 0;
            tmp += selectedDigits[i];
            tmp = tmp * 10;
            for(int j = 0; j < 5; j++) {
                if (i == j) {
                    continue;
                }
                tmp = tmp + selectedDigits[j];
                tmp = tmp * 10;
                for (int k = 0; k < 5; k++) {
                    if (i == k || j == k) {
                        continue;
                    }
                    tmp = tmp + selectedDigits[k];
                    ret[count++] = tmp;
                    tmp = tmp - selectedDigits[k];
                }
                tmp = tmp / 10;
                tmp = tmp - selectedDigits[j];
            }
        }
        return ret;
    }
}

public class Main2 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int[] res;
            
        int selectedDigits_size = 0;
        selectedDigits_size = in.nextInt();
        int[] selectedDigits = new int[selectedDigits_size];
        for(int selectedDigits_i = 0; selectedDigits_i < selectedDigits_size; selectedDigits_i++) {
            selectedDigits[selectedDigits_i] = in.nextInt();
        }

        if(in.hasNextLine()) {
          in.nextLine();
        }

        res = new Solution().ThreeDigitNumbers (selectedDigits);
        for(int res_i=0; res_i < res.length; res_i++) {
            System.out.println(String.valueOf(res[res_i]));
        }
    }
}
